﻿using System;
using System.Collections.Generic;
using System.Text;
using deFramework;

namespace deFramework.Base
{
    /// <summary>
    /// 
    /// </summary>
    public class BaseSharePointPage : Microsoft.SharePoint.WebControls.LayoutsPageBase //System.Web.UI.Page 
    {

        /// <summary>
        /// 
        /// </summary>
        public Common.PresentationContext MyContext = null;


        #region "Events - OnInit, Render"

        /// <summary>
        /// 
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            Microsoft.SharePoint.SPWeb currentWeb = Microsoft.SharePoint.SPContext.Current.Web;
            try { this.MyContext = new Common.PresentationContext(ref currentWeb, this); }
            catch (Exception ex) { this.Response.Redirect("http://localhost/default.aspx?oops=" + ex.Message); }  
            //this.mContext.IntegrateSpWeb(ref currentWeb, this); 
            //this.mContext.IntegrateSpWeb(ref currentWeb, this); 
            base.OnInit(e);
            
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="writer"></param>
        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            base.Render(writer);
            this.MyContext.Dispose();
        }




        #endregion 
		
 
        #region "Polymorphism - PageParamValue, SpWebPropertyValue, SetSpWebProperty, RemoveSpWebProperty"
        
        /// <summary>
        /// 
        /// </summary>
        /// <param name="aVariableName"></param>
        /// <param name="aDefault"></param>
        /// <returns></returns>
        public string PageParamValue(string aVariableName, string aDefault)
        {
            return this.MyContext.PageParamValue(aVariableName, aDefault);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="aPropertyName"></param>
        /// <param name="aDefault"></param>
        /// <returns></returns>
        public string SpWebPropertyValue(string aPropertyName, string aDefault)
        {
            return this.MyContext.SpWebPropertyValue(aPropertyName, aDefault);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="aPropertyName"></param>
        /// <param name="aValue"></param>
        /// <returns></returns>
        public bool SetSpWebProperty(string aPropertyName, string aValue)
        {
            return this.MyContext.SetSpWebProperty(aPropertyName, aValue);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="aPropertyName"></param>
        /// <returns></returns>
        public bool RemoveSpWebProperty(string aPropertyName)
        {
            return this.MyContext.RemoveSpWebProperty(aPropertyName);
        }


        #endregion

        #region "Polymorphism - MyLog, CurrentException, StandardLog, GotoErrorPage"

        /// <summary>
        /// 
        /// </summary>
        public Common.FrameworkLogging MyLog
        {
            get { return this.MyContext.MyLog; }
        }

        /// <summary>
        /// 
        /// </summary>
        public System.Exception CurrentException
        {
            get
            {
                Exception _ex = null;
                try
                {
                    _ex = this.MyContext.CurrentException;
                }
                catch (Exception ex)
                {
                    _ex = ex;
                }
                return _ex;
            }
            set
            {
                Exception _ex = value;
                try
                {
                    this.MyContext.CurrentException = _ex;
                }
                catch
                {
                    // do nothing 
                }
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="aMethodName"></param>
        /// <param name="aMessage"></param>
        /// <returns></returns>
        public bool StandardLog(string aMethodName, string aMessage)
        {
            return this.MyContext.StandardLog(aMethodName, aMessage);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="aTitle"></param>
        /// <param name="aDescription"></param>
        public void GotoErrorPage(string aTitle, string aDescription)
        {
            this.MyContext.GotoErrorPage(aTitle, aDescription);
        }



        #endregion 





    }
}
